<template>
  <div class='ele-body ele-body-card'>
    <!-- 顶部卡片 -->
    <a-card
      :bordered='true'
      :body-style="{padding: '20px'}">
      <a-form
        ref='form'
        :label-col='{ md: { span: 7 }, sm: { span: 24 } }'
        :wrapper-col='{ md: { span: 17 }, sm: { span: 24 } }'
        @submit='checkAndPushSubmitConfig'
      >
        <a-divider orientation="left">基础设置</a-divider>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='设备名字:' name='deviceName'>
              <a-input v-model:value='form.deviceName' placeholder='请输入设备名字' allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='密码:' name='password'>
              <a-input v-model:value='form.password' placeholder='请输入新密码' allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-divider orientation="left">里程配置</a-divider>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="里程统计开关:" name="odoEnable">
              <a-select v-model:value="form.odoEnable">
                <a-select-option :value="0">disable</a-select-option>
                <a-select-option :value="1">enable</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='里程初始化值(Km):' name='odoMileage'>
              <a-input-number
                :step="0.1"
                string-mode
                :min="0" :max="65535" v-model:value='form.odoMileage' style="width: 180px" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-divider orientation="left">Device working status setting</a-divider>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="LED灯开关:" name="ledon">
              <a-select v-model:value="form.ledon">
                <a-select-option :value="0">disable</a-select-option>
                <a-select-option :value="1">enable</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="Power Saving Mode:" name="powerSaveMode">
              <a-select v-model:value="form.powerSaveMode">
                <a-select-option :value="0">disable</a-select-option>
                <a-select-option :value="1">deep saving mode</a-select-option>
                <a-select-option :value="2">low saving mode</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="Backup battle On:" name="backupBatteryOn">
              <a-select v-model:value="form.backupBatteryOn">
                <a-select-option :value="0">disable</a-select-option>
                <a-select-option :value="1">enable</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="Backup battle mode:" name="backupBatteryChargeMode">
              <a-select v-model:value="form.backupBatteryChargeMode">
                <a-select-option :value="0">charge on need</a-select-option>
                <a-select-option :value="1">charge after ignition on</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-divider orientation="left">Mask Setting</a-divider>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='Report Item Mask:' name='reportCompositionMask'>
              <a-checkbox v-model:checked="reportCompositionMaskCheck.speed">Speed</a-checkbox>
              <a-checkbox v-model:checked="reportCompositionMaskCheck.azmuth">Azmuth</a-checkbox>
              <a-checkbox v-model:checked="reportCompositionMaskCheck.altitude">Altitude</a-checkbox>
              <a-checkbox v-model:checked="reportCompositionMaskCheck.cellinfo">GSM tower data</a-checkbox>
              <a-checkbox v-model:checked="reportCompositionMaskCheck.mileage">Mileage</a-checkbox>
              <a-checkbox v-model:checked="reportCompositionMaskCheck.sendtime">Send Time</a-checkbox>
              <a-checkbox v-model:checked="reportCompositionMaskCheck.devicename">Device Name</a-checkbox>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='Position Append Mask:' name='positionAppendMask'>
              <a-checkbox v-model:checked="positionAppendMaskCheck.satellites">The number of satellites in view for the current position</a-checkbox>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='Event Mask:' name='eventMask'>
              <a-checkbox v-model:checked="eventMaskCheck.gtpna">+RESP:GTPNA</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtpfa">+RESP:GTPFA</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtmpn">+RESP:GTMPN</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtmpf">+RESP:GTMPF</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.reserverd1">Reserved</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtbpl">+RESP:GTBPL</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtbtc">+RESP:GTBTC</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtstc">+RESP:GTSTC</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtstt">+RESP:GTSTT</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.reserverd2">Reserved</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtpdp">+RESP:GTPDP</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtrtl">+RESP:GTRTL</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.ignition">+RESP:GTIGN/GTIGF/GTVGN/GTVGF</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.off">+RESP:GTIGL/GTVGL</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtexp">+RESP:GTEXP</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtpnr">+RESP:GTPNR</a-checkbox>
              <a-checkbox v-model:checked="eventMaskCheck.gtpfr">+RESP:GTPFR</a-checkbox>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="GSM Report enable:" name="cellInfoReportMode">
              <a-select v-model:value="form.cellInfoReportMode">
                <a-select-option :value="0">禁止</a-select-option>
                <a-select-option :value="4">allow the cell info report after failed the get gps position</a-select-option>
                <a-select-option :value="8">report the message +RESP:GTGSM after getting gps position success</a-select-option>
                <a-select-option :value="12">report the message +RESP:GTGSM in any situation if cell info avaliable</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='GSM Report Trigger:' name='cellInfoReportTrigger'>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.gtrtl">+RESP:GTRTL</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.gtlbc">+RESP:GTLBC</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.gtfri">+RESP:GTFRI/GTERI</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.gtsos">+RESP:GTSOS</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.gttow">+RESP:GTTOW</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd1">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd2">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd3">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd4">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd5">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd6">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd7">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd8">Reserverd</a-checkbox>
              <a-checkbox v-model:checked="cellInfoReportTriggerCheck.reserverd9">Reserverd</a-checkbox>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-divider orientation="left">Other Function Settings</a-divider>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="Report Enable:" name="infoReportEnable">
              <a-select v-model:value="form.infoReportEnable">
                <a-select-option :value="0">禁止</a-select-option>
                <a-select-option :value="1">开启</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='Report频率(秒):' name='infoReportInterval'>
              <a-input-number :min="0" :max="86400" v-model:value='form.infoReportInterval' style="width: 180px" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>

        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="Agps model:" name="agpsMode">
              <a-select v-model:value="form.agpsMode">
                <a-select-option :value="0">禁止</a-select-option>
                <a-select-option :value="1">开启</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>

        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="location mask(高字节):" name="agpsModeHighBit">
              <a-select v-model:value="locationRequestMaskObj.highBit">
                <a-select-option :value="0">ignore sms location request</a-select-option>
                <a-select-option :value="1">report the current location(+RESP:GTLBC) to server</a-select-option>
                <a-select-option :value="2">Send current location with google map link to caller id vias sms</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>
        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="location mask(低字节):" name="agpsModeLowBit">
              <a-select v-model:value="locationRequestMaskObj.lowBit">
                <a-select-option :value="0">hang up only</a-select-option>
                <a-select-option :value="1">hang up and report the current location(+RESP:GTLBC) to server</a-select-option>
                <a-select-option :value="2">hang up the call and Send current location with google map link to caller id vias sms</a-select-option>
                <a-select-option :value="3">hang up and report the current location(+RESP:GTLBC) to server,simultaneously Send current location with google map link to caller id vias sms</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>

        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label="Gnss work mode:" name="gnssWorkModel">
              <a-select v-model:value="form.gnssWorkModel">
                <a-select-option :value="0">GPS and GLONASS positioning systems</a-select-option>
                <a-select-option :value="1">GPS positioning system</a-select-option>
                <a-select-option :value="4">GPS and BeiDou positoning systems</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>

        <a-row :gutter='8'>
          <a-col :md='14' :sm='24' :xs='24'>
            <a-form-item label='Gnss lost time(分):' name='gnssLostTime'>
              <a-input-number :min="0" :max="30" v-model:value='form.gnssLostTime' style="width: 180px" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24'>
          </a-col>
        </a-row>

        <a-row :gutter='8'>
          <a-col :md='2' :sm='24' :xs='24'>
          </a-col>
          <a-col :md='8' :sm='24' :xs='24'>
            <a-button type='primary' html-type='submit' :loading='formSubmitLoading'>
              提交
            </a-button>
            <a-button style="margin-left: 25px;" type='primary' html-type='button' @click='readCFG' :loading='readLoading'>
              读取
            </a-button>
          </a-col>
          <a-col :md='8' :sm='24' :xs='24'>
          </a-col>
          <a-col :md='6' :sm='24' :xs='24'></a-col>
        </a-row>
      </a-form>
    </a-card>
  </div>
</template>

<script>
import {DeviceCommandDownQueueApi} from '@/api/property/DeviceCommandDownQueueApi';
import { message } from 'ant-design-vue';
import {VehicleConfigGlobalApi} from "@/api/property/vechile/VehicleConfigGlobalApi";

export default {
  name: 'DeviceVehicleConfigDeviceglobal',
  components: {

  },
  props: {
    data: Object
  },
  async created() {
    this.getDetail();
  },
  data() {
    return {
      form : {},
      currentConfig : {},
      reportCompositionMaskCheck : {},
      positionAppendMaskCheck : {},
      eventMaskCheck : {},
      cellInfoReportTriggerCheck : {},
      locationRequestMaskObj :  {},
      loading : false,

      formSubmitLoading : false,
      formSubmitTimer : undefined,

      readLoading : false,
      readTimer : undefined
    };
  },
  methods: {
    getDetail() {
      let that = this;
      VehicleConfigGlobalApi.detail({"recordId" : this.data.recordId}).then(result => {
        that.form = result || {};
        let reportCompositionMask = that.form.reportCompositionMask || 0;
        that.reportCompositionMaskCheck.speed = (reportCompositionMask & 1) == 1;
        that.reportCompositionMaskCheck.azmuth = ((reportCompositionMask >> 1) & 1) == 1;
        that.reportCompositionMaskCheck.altitude = ((reportCompositionMask >> 2) & 1) == 1;
        that.reportCompositionMaskCheck.cellinfo = ((reportCompositionMask >> 3) & 1) == 1;
        that.reportCompositionMaskCheck.mileage = ((reportCompositionMask >> 4) & 1) == 1;
        that.reportCompositionMaskCheck.sendtime = ((reportCompositionMask >> 5) & 1) == 1;
        that.reportCompositionMaskCheck.devicename = ((reportCompositionMask >> 6) & 1) == 1;

        let positionAppendMask = that.form.positionAppendMask || 0;
        that.positionAppendMaskCheck.satellites = (positionAppendMask & 1) == 1;

        let eventMask = that.form.eventMask || 0;
        that.eventMaskCheck.gtpna = (eventMask & 1) == 1;
        that.eventMaskCheck.gtpfa = ((eventMask >> 1) & 1) == 1;
        that.eventMaskCheck.gtmpn = ((eventMask >> 2) & 1) == 1;
        that.eventMaskCheck.gtmpf = ((eventMask >> 3) & 1) == 1;
        that.eventMaskCheck.reserverd1 = ((eventMask >> 4) & 1) == 1;
        that.eventMaskCheck.gtbpl = ((eventMask >> 5) & 1) == 1;
        that.eventMaskCheck.gtbtc = ((eventMask >> 6) & 1) == 1;
        that.eventMaskCheck.gtstc = ((eventMask >> 7) & 1) == 1;
        that.eventMaskCheck.gtstt = ((eventMask >> 8) & 1) == 1;
        that.eventMaskCheck.reserverd2 = ((eventMask >> 9) & 1) == 1;
        that.eventMaskCheck.gtpdp = ((eventMask >> 10) & 1) == 1;
        that.eventMaskCheck.gtrtl = ((eventMask >> 11) & 1) == 1;
        that.eventMaskCheck.ignition = ((eventMask >> 12) & 1) == 1;
        that.eventMaskCheck.off = ((eventMask >> 13) & 1) == 1;
        that.eventMaskCheck.gtexp = ((eventMask >> 14) & 1) == 1;
        that.eventMaskCheck.gtpnr = ((eventMask >> 15) & 1) == 1;
        that.eventMaskCheck.gtpfr = ((eventMask >> 16) & 1) == 1;

        let cellInfoReportTrigger = that.form.cellInfoReportTrigger || 0;
        that.cellInfoReportTriggerCheck.gtrtl = (cellInfoReportTrigger & 1) == 1;
        that.cellInfoReportTriggerCheck.gtlbc = ((cellInfoReportTrigger >> 1) & 1) == 1;
        that.cellInfoReportTriggerCheck.gtfri = ((cellInfoReportTrigger >> 2) & 1) == 1;
        that.cellInfoReportTriggerCheck.gtsos = ((cellInfoReportTrigger >> 3) & 1) == 1;
        that.cellInfoReportTriggerCheck.gttow = ((cellInfoReportTrigger >> 4) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd1 = ((cellInfoReportTrigger >> 5) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd2 = ((cellInfoReportTrigger >> 6) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd3 = ((cellInfoReportTrigger >> 7) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd4 = ((cellInfoReportTrigger >> 8) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd5 = ((cellInfoReportTrigger >> 9) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd6 = ((cellInfoReportTrigger >> 10) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd7 = ((cellInfoReportTrigger >> 11) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd8 = ((cellInfoReportTrigger >> 12) & 1) == 1;
        that.cellInfoReportTriggerCheck.reserverd9 = ((cellInfoReportTrigger >> 13) & 1) == 1;

        let locationRequestMask = that.form.locationRequestMask || 0;
        that.locationRequestMaskObj.highBit = parseInt(locationRequestMask / 10);
        that.locationRequestMaskObj.lowBit = locationRequestMask - (that.locationRequestMaskObj.highBit * 10);
        that.currentConfig = JSON.parse(JSON.stringify(result || {}));
      });
    },

    checkProcess(sceneDictate, clearCallback, callback) {
      let params = {
        recordId: this.data.recordId,
        sceneDictate: sceneDictate
      };
      let result = DeviceCommandDownQueueApi.workingDetail2(params);
      result
        .then(result => {
          if (!result || !result.dcdqId) { //处理完成了
            clearCallback && clearCallback(); //去掉菊花+清除循环调用
            callback && callback(); //用户自定义
          }
        })
        .catch(() => {
          clearCallback && clearCallback(); //去掉菊花+清除循环调用
        });
    },


    //-------提交
    clearSubmitConfig(){
      this.formSubmitLoading = false;
      clearInterval(this.formSubmitTimer);
    },

    checkSubmitConfig(){
      let that = this;
      this.checkProcess(2, this.clearSubmitConfig, function(){
        that.getDetail();
      });
    },

    checkAndPushSubmitConfig() {
      let workerDetailparams = {
        recordId: this.data.recordId,
        sceneDictate: 2
      };
      let that = this;
      let existWorkerResult = DeviceCommandDownQueueApi.workingDetail2(workerDetailparams);
      existWorkerResult
        .then(workResult => {
          console.log(workResult);
          if (!workResult || !workResult.dcdqId) { //处理完成了
            that.pushSubmitConfigSubmit();
          } else {
            message.error('上一个配置还在推送中，请稍后重试');
            return;
          }
        })
        .catch((e) => {
          message.error(e);
        });
    },
    pushSubmitConfigSubmit() {
      this.loading = true;
      let reportCompositionMask = this.reportCompositionMaskCheck.speed ? 1 : 0;
      if (this.reportCompositionMaskCheck.azmuth) {
        reportCompositionMask = reportCompositionMask | ((this.reportCompositionMaskCheck.azmuth ? 1 : 0) << 1);
      }
      if (this.reportCompositionMaskCheck.altitude) {
        reportCompositionMask = reportCompositionMask | ((this.reportCompositionMaskCheck.altitude ? 1 : 0) << 2);
      }
      if (this.reportCompositionMaskCheck.cellinfo) {
        reportCompositionMask = reportCompositionMask | ((this.reportCompositionMaskCheck.altitude ? 1 : 0) << 3);
      }
      if (this.reportCompositionMaskCheck.mileage) {
        reportCompositionMask = reportCompositionMask | ((this.reportCompositionMaskCheck.mileage ? 1 : 0) << 4);
      }
      if (this.reportCompositionMaskCheck.sendtime) {
        reportCompositionMask = reportCompositionMask | ((this.reportCompositionMaskCheck.sendtime ? 1 : 0) << 5);
      }
      if (this.reportCompositionMaskCheck.devicename) {
        reportCompositionMask = reportCompositionMask | ((this.reportCompositionMaskCheck.devicename ? 1 : 0) << 6);
      }
      this.form.reportCompositionMask = reportCompositionMask;

      this.form.positionAppendMask = this.positionAppendMaskCheck.satellites ? 1 : 0;

      let eventMask = this.eventMaskCheck.gtpna ? 1 : 0;
      if (this.eventMaskCheck.gtpfa) {
        eventMask = eventMask | ((this.eventMaskCheck.gtpfa ? 1 : 0) << 1);
      }
      if (this.eventMaskCheck.gtmpn) {
        eventMask = eventMask | ((this.eventMaskCheck.gtmpn ? 1 : 0) << 2);
      }
      if (this.eventMaskCheck.gtmpf) {
        eventMask = eventMask | ((this.eventMaskCheck.gtmpf ? 1 : 0) << 3);
      }
      if (this.eventMaskCheck.reserverd1) {
        eventMask = eventMask | ((this.eventMaskCheck.reserverd1 ? 1 : 0) << 4);
      }
      if (this.eventMaskCheck.gtbpl) {
        eventMask = eventMask | ((this.eventMaskCheck.gtbpl ? 1 : 0) << 5);
      }
      if (this.eventMaskCheck.gtbtc) {
        eventMask = eventMask | ((this.eventMaskCheck.gtbtc ? 1 : 0) << 6);
      }
      if (this.eventMaskCheck.gtstc) {
        eventMask = eventMask | ((this.eventMaskCheck.gtstc ? 1 : 0) << 7);
      }
      if (this.eventMaskCheck.gtstt) {
        eventMask = eventMask | ((this.eventMaskCheck.gtstt ? 1 : 0) << 8);
      }
      if (this.eventMaskCheck.reserverd2) {
        eventMask = eventMask | ((this.eventMaskCheck.reserverd2 ? 1 : 0) << 9);
      }
      if (this.eventMaskCheck.gtpdp) {
        eventMask = eventMask | ((this.eventMaskCheck.gtpdp ? 1 : 0) << 10);
      }
      if (this.eventMaskCheck.gtrtl) {
        eventMask = eventMask | ((this.eventMaskCheck.gtrtl ? 1 : 0) << 11);
      }
      if (this.eventMaskCheck.ignition) {
        eventMask = eventMask | ((this.eventMaskCheck.ignition ? 1 : 0) << 12);
      }
      if (this.eventMaskCheck.off) {
        eventMask = eventMask | ((this.eventMaskCheck.off ? 1 : 0) << 13);
      }
      if (this.eventMaskCheck.gtexp) {
        eventMask = eventMask | ((this.eventMaskCheck.gtexp ? 1 : 0) << 14);
      }
      if (this.eventMaskCheck.gtpnr) {
        eventMask = eventMask | ((this.eventMaskCheck.gtpnr ? 1 : 0) << 15);
      }
      if (this.eventMaskCheck.gtpfr) {
        eventMask = eventMask | ((this.eventMaskCheck.gtpfr ? 1 : 0) << 16);
      }
      this.form.eventMask = eventMask;

      let cellInfoReportTrigger = this.cellInfoReportTriggerCheck.gtrtl ? 1 : 0;
      if (this.cellInfoReportTriggerCheck.gtlbc) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.gtlbc ? 1 : 0) << 1);
      }
      if (this.cellInfoReportTriggerCheck.gtfri) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.gtfri ? 1 : 0) << 2);
      }
      if (this.cellInfoReportTriggerCheck.gtsos) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.gtsos ? 1 : 0) << 3);
      }
      if (this.cellInfoReportTriggerCheck.gttow) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.gttow ? 1 : 0) << 4);
      }
      if (this.cellInfoReportTriggerCheck.reserverd1) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd1 ? 1 : 0) << 5);
      }
      if (this.cellInfoReportTriggerCheck.reserverd2) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd2 ? 1 : 0) << 6);
      }
      if (this.cellInfoReportTriggerCheck.reserverd3) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd3 ? 1 : 0) << 7);
      }
      if (this.cellInfoReportTriggerCheck.reserverd4) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd4 ? 1 : 0) << 8);
      }
      if (this.cellInfoReportTriggerCheck.reserverd5) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd5 ? 1 : 0) << 9);
      }
      if (this.cellInfoReportTriggerCheck.reserverd6) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.reportCompositionMaskCheck.reserverd6 ? 1 : 0) << 10);
      }
      if (this.cellInfoReportTriggerCheck.reserverd7) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd7 ? 1 : 0) << 11);
      }
      if (this.cellInfoReportTriggerCheck.reserverd8) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd8 ? 1 : 0) << 12);
      }
      if (this.cellInfoReportTriggerCheck.reserverd9) {
        cellInfoReportTrigger = cellInfoReportTrigger | ((this.cellInfoReportTriggerCheck.reserverd9 ? 1 : 0) << 13);
      }
      this.form.cellInfoReportTrigger = cellInfoReportTrigger;

      let locationRequestMask = ((this.locationRequestMaskObj.highBit ? this.locationRequestMaskObj.highBit : 0) * 10)
        + (this.locationRequestMaskObj.lowBit ? this.locationRequestMaskObj.lowBit : 0);
      this.form.locationRequestMask = locationRequestMask;
      let updateDataRecord = {
        recordId: this.data.recordId,
        templateCode: 'vehicle',
        updateData: JSON.stringify({ old: this.currentConfig, update: this.form}),
        dictate : 2, //AT+GTQSS=
        sceneDictate : 2 //服务器连接配置
      };
      let result = DeviceCommandDownQueueApi.add(updateDataRecord);
      result
        .then(result => {
          this.loading = false;
          message.success(result.message);

          this.formSubmitLoading = true; //转圈
          this.formSubmitTimer = setInterval(this.checkSubmitConfig, 5000);
        })
        .catch(() => {
          this.loading = false;
        });
    },

    //--读取
    clearReadSubmitConfig(){
      this.readLoading = false;
      clearInterval(this.readTimer);
    },

    checkReadSubmitConfig(){
      let that = this;
      this.checkProcess(601, this.clearReadSubmitConfig, function(){
        that.getDetail();
      });
    },

    readCFG() {
      let workerDetailParams = {
        recordId: this.data.recordId,
        sceneDictate: 601
      };
      let that = this;
      let existWorkerResult = DeviceCommandDownQueueApi.workingDetail2(workerDetailParams);
      existWorkerResult
        .then(workResult => {
          console.log(workResult);
          if (!workResult || !workResult.dcdqId) { //处理完成了
            that.pushSubmitReadSubmit();
          } else {
            message.error('上一个配置还在推送中，请稍后重试');
            return;
          }
        })
        .catch((e) => {
          message.error(e);
        });
    },
    pushSubmitReadSubmit() {
      this.loading = true;
      let updateDataRecord = {
        recordId: this.data.recordId,
        templateCode: 'vehicle',
        updateData: JSON.stringify({}),
        dictate : 601, //读取CFG
        sceneDictate : 601
      };
      let result = DeviceCommandDownQueueApi.add(updateDataRecord);
      result
        .then(result => {
          this.loading = false;
          message.success(result.message);

          this.readLoading = true; //转圈
          this.readTimer = setInterval(this.checkReadSubmitConfig, 5000);
        })
        .catch(() => {
          this.loading = false;
        });
    },

  }
};
</script>
<style scoped>
/** 用户卡片 */
.workplace-user-card .ele-cell-content {
  overflow: hidden;
}

.workplace-user-card h4 {
  margin-bottom: 6px;
}
</style>
